import React from 'react'

function asyncComponent (componentLoadFun) {
    let component = null

    return function (props) {
        const [componentLoaded, load] = React.useState(!!component)
        if (componentLoaded) {
            return React.createElement(
                component,
                props
            )
        } else {
            componentLoadFun().then(c => {
                component = c
                load(true)
            })

            return <div>loading...</div>
        }
    }
}

export { asyncComponent }
